<?php
/**
 *This file is part of Minimal Ablog.
 * Minimal Ablog is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Minimal Ablog is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Minimal Ablog.  If not, see <http://www.gnu.org/licenses/>.
*/

error_reporting(E_ALL);
/* Constant Global of dir and Path */
define('DEBUG_MODE', true); //please comment if is in production!!!!!!
define('PATH_ABS', substr(str_replace('\\', '/', dirname(__FILE__)) , 0, -6), true);
define('PATH_CORE', realpath(PATH_ABS.'../core'), true);
define('PATH_CACHE', PATH_CORE.'/cache/', true);
/*Function of autoload for class*/
function __autoload($s_classname){
	$s_classname = str_replace('_', '/', strtolower($s_classname));
	$s_file = PATH_CORE.'/libs/'.$s_classname.'.class.php';
	if(file_exists($s_file)) {
		include($s_file);
	}else {
		throw(new ABException("Dependencias no satisfechas falta la clase $s_classname"));
	}
}

ABConf::load('config');
$a_conf = ABConf::getAll();
define('AB_TABLE_PREFIX', 'ablog_', true);
define('PATH_TPL', PATH_CORE.'/template/', true);
define('PATH_IMG', PATH_ABS.'/images/', true);
define('PATH_SCRIPT', PATH_ABS.'/script/', true);
define('PATH_LOGFILE', PATH_ABS.'config/log.txt', true);
define('HOST_NAME','http://'.$_SERVER['HTTP_HOST']. $a_conf['path'],true);
define('HOST_ADMIN', HOST_NAME.'admin/', true);
define('HOST_SCRIPT', HOST_NAME.'script/', true);
define('HOST_IMG', HOST_NAME.'images/', true);
$s_urlp = $a_conf['shorturl'] ? HOST_NAME.'pages/view/':HOST_NAME.'index.php?url=';
$s_urlc = $a_conf['shorturl'] ? HOST_NAME.'pages/tag/' : HOST_NAME.'category.php?url=';
define('URL_POST', $s_urlp, true);
define('URL_TAG', $s_urlc, true);
//crea la instancia  de conexion
dbConnect::getInstance(array('server' => $a_conf['server'], 'user' =>$a_conf['user'], 'pass' => $a_conf['keypass'], 'dbname' => $a_conf['dbname']));
unset($s_urlc, $s_urlp, $a_conf);

setlocale(LC_ALL, 'es', 'es_ve');
set_error_handler(array('ABException', 'hError'));
set_exception_handler(array('ABException', 'hException'));
date_default_timezone_set('UTC');
//Use of path info for get variables
if(!empty($_SERVER['PATH_INFO'])){
	$var_array = explode('/', $_SERVER['PATH_INFO']);
	foreach($var_array as $value){
		if(empty($value))continue;
		$temp = explode(':', $value);
	$_GET[$temp[0]] = str_replace('-', ' ', $temp[1]);
	}
	unset($var_array, $temp);
}
?>
